import {coldService as request} from '@/utils/request'

function formData(data) {
  const form = new FormData()
  for (const key in data) {
    if (data[key]) {
      form.append(key, data[key])
    }
  }
  return form
}

/**
 * @param {{
*  current: number,
 * size: number,
 * staDate: string,
 * endDate: string,
 * taskName: string,
 * dbTableName: string,
 * taskState: string
 * }} params
 */
function cbCompAuditTask(params) {
  return request({
    url: '/cbCompAuditTask/page',
    method: 'get',
    params
  })
}

/**
 * @param {{
*  current: number,
 * size: number,
 * taskId: number
 * dbTableName: string,
 * taskState: string
 * }} params
 */
function cbCompSyncAudit(params) {
  return request({
    url: '/cbCompSyncAudit/page',
    method: 'get',
    params
  })
}

/**
 * @param {{
  *  logPath: string
 * }} params
*/
function download(params) {
  return request({
    url: '/messagecenter/downLoadLog',
    method: 'get',
    params
  })
}

/**
 * @param {{
  *  mark: string
  *  flag: string
  *  dbName: string
  *  taskName: string
  * }} data
  * @returns {Promise}
  * */
function rerunCount(data) {
  return request({
    url: '/cbCompAuditTask/rerunCount',
    method: 'post',
    data: formData(data)
  })
}

/**
 * @param {{
*  auditId: string
* }} data
* @returns {Promise}
* */
function rerunCountONE(data) {
  return request({
    url: '/cbCompAuditTask/rerunCountONE',
    method: 'post',
    data: formData(data)
  })
}

function getAuditBlackList(params) {
  return request({
    url: '/cbSyncAuditBlackList/page',
    method: 'get',
    params
  })
}

function addAuditBlackList(data) {
  return request({
    url: '/cbSyncAuditBlackList',
    method: 'post',
    data
  })
}

function editAuditBlackList(data) {
  return request({
    url: '/cbSyncAuditBlackList',
    method: 'put',
    data
  })
}

function delAuditBlackList(id) {
  return request({
    url: `/cbSyncAuditBlackList/${id}`,
    method: 'delete'
  })
}

function cbParamConfig(params) {
  return request({
    url: '/cbparamconfig/page',
    method: 'get',
    params
  })
}

function addCbParamConfig(data) {
  return request({
    url: '/cbparamconfig',
    method: 'post',
    data
  })
}

function editCbParamConfig(data) {
  return request({
    url: '/cbparamconfig',
    method: 'put',
    data
  })
}

function delCbParamConfig(id) {
  return request({
    url: `/cbparamconfig/${id}`,
    method: 'delete'
  })
}

function pauseCbParamConfig() {
  return request({
    url: '/cbparamconfig/updateStatus',
    method: 'put',
    data: {
      paramName: 'fullCountStatus',
      paramValue: 'block'
    }
  })
}

function continueCbCompAuditTask(data) {
  return request({
    url: '/cbCompAuditTask/count',
    method: 'post',
    data: formData(data)
  })
}

function ltContinue(data) {
  return request({
    url: '/cbCompAuditTask/serialConut',
    method: 'post',
    data: formData(data)
  })
}

function cbSyncFullAudit(params) {
  return request({
    url: '/cbCompSyncAuditDetail/page',
    method: 'get',
    params
  })
}

function reRunFullAudit(data) {
  return request({
    url: '/cbCompSyncAuditDetail/rerunAudit',
    method: 'post',
    data: formData(data)
  })
}
function reRunFullAuditOne(data) {
  return request({
    url: '/cbCompSyncAuditDetail/rerunAuditONE',
    method: 'post',
    data: formData(data)
  })
}

function continueFullAudit(data) {
  return request({
    url: '/cbCompSyncAuditDetail/contrastDataNum',
    method: 'post',
    data: formData(data)
  })
}

function pauseFullAudit() {
  return request({
    url: '/cbparamconfig/updateStatus',
    method: 'put',
    data: {
      paramName: 'fullAuditStatus',
      paramValue: 'block'
    }
  })
}

function cbTask(params) {
  return request({
    url: '/cbTask/page',
    method: 'get',
    params
  })
}

function cbTable(params) {
  return request({
    url: '/cbTable/page',
    method: 'get',
    params
  })
}

function cbDataChange(params) {
  return request({
    url: '/cbDataChange/page',
    method: 'get',
    params
  })
}

function cbAllTable(params) {
  return request({
    url: '/cbAllTable/page',
    method: 'get',
    params
  })
}

function cbRestoreTask(params) {
  return request({
    url: '/cbRestoreTask/page',
    method: 'get',
    params
  })
}
function cbRestoreList(params) {
  return request({
    url: '/cbRestoreList/page',
    method: 'get',
    params
  })
}

function pushRestoreTask(id) {
  return request({
    url: `/cbRestoreTask/postToCluster/${id}`,
    method: 'post'
  })
}

function createRestoreTask(data) {
  return request({
    url: '/cbRestoreTask',
    method: 'post',
    data: formData(data)
  })
}
function pauseRestoreTask(id) {
  return request({
    url: `/cbRestoreTask/pause/${id}`,
    method: 'post'
  })
}
function continueRestoreTask(id) {
  return request({
    url: `/cbRestoreTask/continue/${id}`,
    method: 'post'
  })
}

function getAgentInfo(params) {
  return request({
    url: '/agent/page',
    method: 'get',
    params
  })
}

function getCBNasInfo(params) {
  return request({
    url: '/cbNas/page',
    method: 'get',
    params
  })
}

function addCBNasInfo(data) {
  return request({
    url: `/cbNas`,
    method: 'post',
    data
  })
}
function editCBNasInfo(data) {
  return request({
    url: `/cbNas`,
    method: 'put',
    data
    // data: formData(data)
  })
}

function delCBNasInfo(id) {
  return request({
    url: `/cbNas/${id}`,
    method: 'delete'
  })
}

function toggleNasStatus(id) {
  return request({
    url: `/cbNas/toggle/${id}`,
    method: 'put'
  })
}

function toggleNasAgentStatus(id) {
  return request({
    url: `/cbNasAgentConfig/toggle/${id}`,
    method: 'put'
  })
}

function toggleNasDatabaseStatus(id) {
  return request({
    url: `/cbNasDatabaseConfig/toggle/${id}`,
    method: 'put'
  })
}

function getNasAgentConfig(params) {
  return request({
    url: '/cbNasAgentConfig/page',
    method: 'get',
    params
  })
}

function addNasAgentConfig(data) {
  return request({
    url: `/cbNasAgentConfig`,
    method: 'post',
    data
  })
}
function editNasAgentConfig(data) {
  return request({
    url: `/cbNasAgentConfig`,
    method: 'put',
    data
  })
}

function delNasAgentConfig(id) {
  return request({
    url: `/cbNasAgentConfig/${id}`,
    method: 'delete'
  })
}

function getNasDatabaseConfig(params) {
  return request({
    url: '/cbNasDatabaseConfig/page',
    method: 'get',
    params
  })
}

function addNasDatabaseConfig(data) {
  return request({
    url: `/cbNasDatabaseConfig`,
    method: 'post',
    data
  })
}
function editNasDatabaseConfig(data) {
  return request({
    url: `/cbNasDatabaseConfig`,
    method: 'put',
    data
  })
}

function delNasDatabaseConfig(id) {
  return request({
    url: `/cbNasDatabaseConfig/${id}`,
    method: 'delete'
  })
}

function getUsefulNas(params) {
  return request({
    url: '/cbNas/usefulNas',
    method: 'get',
    params
  })
}

export default {cbCompAuditTask, cbCompSyncAudit, download, rerunCount, rerunCountONE, getAuditBlackList, delAuditBlackList, addAuditBlackList, editAuditBlackList, cbParamConfig, addCbParamConfig, editCbParamConfig, delCbParamConfig, pauseCbParamConfig, continueCbCompAuditTask, ltContinue, cbSyncFullAudit, reRunFullAudit, reRunFullAuditOne, continueFullAudit, pauseFullAudit,
  cbTask, cbTable, cbDataChange, cbAllTable, cbRestoreTask, cbRestoreList, pushRestoreTask, createRestoreTask, pauseRestoreTask, continueRestoreTask, getAgentInfo, getCBNasInfo, addCBNasInfo, editCBNasInfo, delCBNasInfo, getNasAgentConfig, addNasAgentConfig, editNasAgentConfig, delNasAgentConfig,
  getNasDatabaseConfig, addNasDatabaseConfig, editNasDatabaseConfig, delNasDatabaseConfig, toggleNasStatus, toggleNasAgentStatus, toggleNasDatabaseStatus, getUsefulNas
}

